
#include <Archaism/Color.h>

_BeginNamespace(Radix)

Color::Color(real r, real g, real b, real a)
	:r(r), g(g), b(b), a(a)
{}

Color::Color(const Color& c)
	:r(c.r), g(c.g), b(c.b), a(c.a)
{}

Color::~Color()
{}

Color& Color::operator=(const Color& c)
{
	r = c.r;
	g = c.g;
	b = c.b;
	a = c.a;
	return *this;
}

Color Color::operator-()
{
	real nr = (real)(1.0 - r);
	real ng = (real)(1.0 - g);
	real nb = (real)(1.0 - b);
	real na = (real)(1.0 - a);
	return Color(nr, ng, nb, na);
}

Color Color::operator+(const Color& c)
{
	return Color(r+c.r, g+c.g, b+c.b, a+c.a);
}

Color Color::operator-(const Color& c)
{
	return Color(r-c.r, g-c.g, b-c.b, a-c.a);
}

Color Color::operator*(const Color& c)
{
	return Color(r*c.r, g*c.g, b*c.b, a*c.a);
}

Color& Color::operator+=(const Color& c)
{
	r += c.r;
	g += c.g;
	b += c.b;
	a += c.a;
	return *this;
}

Color& Color::operator-=(const Color& c)
{
	r -= c.r;
	g -= c.g;
	b -= c.b;
	a -= c.a;
	return *this;
}

Color& Color::operator*=(const Color& c)
{
	r *= c.r;
	g *= c.g;
	b *= c.b;
	a *= c.a;
	return *this;
}

bool Color::operator==(const Color& c)
{
	return 
		_RealEqual(r, c.r) &&
		_RealEqual(g, c.g) &&
		_RealEqual(b, c.b) &&
		_RealEqual(a, c.a);
}

bool Color::operator!=(const Color& c)
{
	return !(_RealEqual(r, c.r) &&
		_RealEqual(g, c.g) &&
		_RealEqual(b, c.b) &&
		_RealEqual(a, c.a));
}

Color& Color::clamp(real min, real max)
{
	r = r < min ? min : r;
	r = r > max ? max : r;
	g = g < min ? min : g;
	g = g > max ? max : g;
	b = b < min ? min : b;
	b = b > max ? max : b;
	a = a < min ? min : a;
	a = a > max ? max : a;
	return *this;
}

_EndNamespace(Radix)
